﻿using System;
using System.Collections.Generic;
using DAL;
using Entity;
using Utilities;

namespace Business
{
	public class OutNewBusiness
	{
		#region code CMS

        public static List<OutNew> GetOutNewListByPaging(bool isParent, string title, DateTime from, DateTime to, int cate, int stt, int pageIndex, int pageSize, ref int totalRecord)
        {
            var result = FreshCmsDataAccessProvider.OutNew.GetOutNewListByPaging(isParent, title, from, to, cate, stt, pageIndex, pageSize, ref totalRecord);
            return result;
        }

        public static int InsertOutNew(OutNew OutNew)
        {
            var result = FreshCmsDataAccessProvider.OutNew.InsertOutNew(OutNew);
            return result;
        }

        /// <summary>
        /// Hàm UPDATE cho User, có check đúng UserID mới cho UPDATE. Return: -3: không phải bài của ng Update, >0 là ok
        /// </summary>
        /// <param name="OutNew"></param>
        /// <returns></returns>
        public static int UpdateOutNewWithRole(OutNew OutNew)
        {
            var result = FreshCmsDataAccessProvider.OutNew.UpdateOutNewWidthRole(OutNew);
            return result;
        }

        /// <summary>
        /// Hàm UPDATE cho Admin, UPDATE ngay không check USERID
        /// </summary>
        /// <param name="OutNew"></param>
        /// <returns></returns>
        public static int UpdateOutNew(OutNew OutNew)
        {
            var result = FreshCmsDataAccessProvider.OutNew.UpdateOutNew(OutNew);
            return result;
        }

        public static OutNew GetOutNewById(int Id)
        {
            var result = FreshCmsDataAccessProvider.OutNew.GetOutNewById(Id);
            if (result != null)
            {
                result.ThumbImage1 = ImageUtils.GetImageThumb(result.NewImage, Constant.NewAvatar1Width,
                                                              Constant.NewAvatar1Height,
                                                              Constant.ProductAvatarDefault);
                if (result.NewHot == 1) result.ChkHot = "checked";
                if (result.NewTop == 1) result.ChkTop = "checked";
                if (result.NewVideo) result.ChkVideo= "checked";
                if (result.NewPhoto) result.ChkPhoto = "checked";
            }
            return result;
        }

        /// <summary>
        /// Hàm UPDATE FAST cho User, có check đúng UserID mới cho UPDATE. Return: -3: không phải bài của ng Update, >0 là ok
        /// </summary>
        /// <param name="OutNew"></param>
        /// <returns></returns>
        public static int UpdateFastOutNewWithRole(OutNew OutNew)
        {
            var result = FreshCmsDataAccessProvider.OutNew.UpdateFastOutNewWidthRole(OutNew);
            return result;
        }

        /// <summary>
        /// Hàm UPDATE FAST cho Admin, UPDATE ngay không check USERID
        /// </summary>
        /// <param name="OutNew"></param>
        /// <returns></returns>
        public static int UpdateFastOutNew(OutNew OutNew)
        {
            var result = FreshCmsDataAccessProvider.OutNew.UpdateFastOutNew(OutNew);
            return result;
        }

        /// <summary>
        ///  Delete tin cho Super ADMIN (dùng cho xóa vĩnh viễn)
        /// </summary>
        /// <param name="newId"></param>
        /// <returns></returns>
        public static int DeleteOutNew(int newId)
        {
            var result = FreshCmsDataAccessProvider.OutNew.DeleteOutNew(newId);
            return result;
        }

        /// <summary>
        /// Delete tin có check đúng tài khoản mới Delete (dùng cho xóa vĩnh viễn)
        /// </summary>
        /// <param name="newId"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static int DeleteOutNewWithRole(int newId, int userid)
        {
            var result = FreshCmsDataAccessProvider.OutNew.DeleteOutNewWidthRole(newId, userid);
            return result;
        }

        /// <summary>
        /// Update status tin cho Super ADMIN (dùng cho xóa tạm thời và phục hồi)
        /// </summary>
        /// <param name="newId"></param>
        /// <returns></returns>
        public static int UpdateOutNewStatus(int newId, int proStt)
        {
            var result = FreshCmsDataAccessProvider.OutNew.UpdateOutNewStatus(newId, proStt);
            return result;
        }

        /// <summary>
        /// Update status tin dành cho người dùng có check Role (dùng cho xóa tạm thời và phục hồi)
        /// </summary>
        /// <param name="newId"></param>
        /// <param name="proStt"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static int UpdateOutNewStatusWithRole(int newId, int proStt, int userid)
        {
            var result = FreshCmsDataAccessProvider.OutNew.UpdateOutNewStatusWidthRole(newId, proStt, userid);
            return result;
        }

        /// <summary>
        /// Check xem bai viet co dung theo ng viet hay khong, tra ve > 0 la ok
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="newid"></param>
        /// <returns></returns>
        public static int CheckRole(int userid, int newid)
        {
            var result = FreshCmsDataAccessProvider.OutNew.CheckRole(userid, newid);
            return result;
        }

		#endregion
	}
}